#!/user/bin/env python3
# -*- coding: utf-8 -*-

"""
简单选择排序

"""


def select_sort(items, comp=lambda x, y: x < y):
    items = items[:]
    for i in range(len(items) - 1):
        min_index = i
        for j in range(i + 1, len(items)):
            if comp(items[j], items[min_index]):
                min_index = j
        items[i], items[min_index] = items[min_index], items[i]
    return items


# print(select_sort([9, 2, 1, 2, 3, 7]))


def bubble_sort_a(items, comp=lambda x, y: x > y):
    """冒泡排序-简单版"""
    items = items[:]
    for i in range(len(items) - 1):
        swapped = False
        for j in range(len(items) - 1 - i):
            if comp(items[j], items[j + 1]):
                items[j], items[j + 1] = items[j + 1], items[j]
                swapped = True
        if not swapped:
            break
    return items


# print(bubble_sort_a([1, 2, 6, 4, 3, 2, 7]))


def bubble_sort(items, comp=lambda x, y: x > y):
    """
    冒泡排序升级版
    :param items:需要排序的数组
    :param comp: 比较大小的函数
    :return: 排序好的数组
    """
    items = items[:]
    for i in range(len(items) - 1):
        swapped = False
        for j in range(len(items) - 1 - i):
            if comp(items[j], items[j + 1]):
                items[j], items[j + 1] = items[j + 1], items[j]
                swapped = True
        if swapped:
            swapped = False
            for j in range(len(items) - 2 - i, i, -1):
                if comp(items[j - 1], items[j]):
                    items[j], items[j - 1] = items[j - 1], items[j]
                    swapped = True
        if not swapped:
            break
    return items


# print(bubble_sort([3, 2, 7, 6, 3, 2, 4]))


def merge(items1, items2, comp=lambda x, y: x < y):
    """
    合并
    :param items1:已排序的数组一
    :param items2: 已排序的数组二
    :param comp: 比较大小的函数
    :return: 归并后的数组
    """
    items = []
    index1, index2 = 0, 0
    while index1 < len(items1) and index2 < len(items2):
        if comp(items1[index1], items2[index2]):
            items.append(items1[index1])
            index1 += 1
        else:
            items.append(items2[index2])
            index2 += 1
    items += items1[index1:]
    items += items2[index2:]
    return items


def merge_sort(items, comp=lambda x, y: x < y):
    return _merge_sort(list(items), comp)


def _merge_sort(items, comp):
    if len(items) < 2:
        return items
    mid = len(items) // 2
    left = _merge_sort(items[:mid], comp)
    right = _merge_sort(items[mid:], comp)
    return merge(left, right, comp)


# print(merge_sort([3, 5, 2, 6, 4, 2, 1, 3]))


def bin_search(items, key):
    """
    二分查找发
    :param items:查找有序数组
    :param key: 需要查找的关键字
    :return: 关键字在数组中的位置
    """
    start, end = 0, len(items) - 1
    while start <= end:
        mid = (start + end) // 2
        if key > items[mid]:
            start = mid + 1
        elif key < items[mid]:
            end = mid - 1
        else:
            return mid
    return -1


""""
常用算法：
    1.穷举法：对所有可能性进行验证，直到找到正确答案
    2.贪婪法：在对问题求解时，总是做出在当前看来最好的选择
    3.分治法：将一个问题分成两个或者更多相同或相似的问题，将子问题的解合并
    4.回溯法：按照条件向前搜索，若搜索到某一步发现原先选择不优或者达不到目标时，退回一步重新选择
    5.动态规划：将待求解问题分成若干个子问题，先求解并保存这些子问题的解
"""

"""
贪婪法例子：
    假设小偷有一个背包，最多能装20公斤赃物，他闯入一户人家，发现如下表所示的物品。
    很显然，他不能把所有物品都装进背包，所以必须确定拿走哪些物品，留下哪些物品
        物品    价格     重量
        电脑    200      20
        收音机  20       4
        钟      175      10
        花瓶    50       2
        书      10       1
        油画    90       9
"""


class Thing(object):

    def __init__(self, name, price, weight):
        self.name = name
        self.price = price
        self.weight = weight

    @property
    def value(self):
        """价格重量比"""
        return self.price / self.weight


def input_thing():
    """输入物品信息"""
    print("请输入物品信息：")
    name_str, price_str, weight_str = input().split()
    return name_str, int(price_str), int(weight_str)


def stole_thing():
    print("请输入能装的重量和总共可以偷的赃物:")
    max_weight, num_of_things = map(int, input().split())
    all_things = []
    for _ in range(num_of_things):
        all_things.append(Thing(*input_thing()))
    all_things.sort(key=lambda x: x.value, reverse=True)
    total_weight = 0
    total_price = 0
    for thing in all_things:
        if total_weight + thing.weight <= max_weight:
            print(f"小偷拿走了{thing.name}")
            total_weight += thing.weight
            total_price += thing.price
    print(f"总价值:{total_price}美元")


# stole_thing()


"""
分治法例子
    快速排序-选择枢轴对元素进行划分，左边都比枢轴小，右边都比枢轴大
"""


def quick_sort(items, comp=lambda x, y: x <= y):
    items = list(items)[:]
    _quick_sort(items, 0, len(items) - 1, comp)
    return items


def _quick_sort(items, start, end, comp):
    if start < end:
        pos = _partition(items, start, end, comp)
        _quick_sort(items, start, pos - 1, comp)
        _quick_sort(items, pos + 1, end, comp)


def _partition(items, start, end, comp):
    pivot = items[end]
    i = start - 1
    for j in range(start, end):
        if comp(items[j], pivot):
            i += 1
            items[i], items[j] = items[j], items[i]
    items[i + 1], items[end] = items[end], items[i + 1]
    return i + 1


# print(quick_sort([1, 2, 2, 6, 4, 3, 5, 9, 3]))


"""
回溯法例子：
    骑士巡逻：将一个国际象棋的骑士放在棋盘上，有什么路径能使它走完棋盘中每一个位置
"""

SIZE = 5
total = 0


def print_board(board):
    for row in board:
        for col in row:
            print(str(col).center(4), end=" ")
        print()


def patrol(board, row, col, step=1):
    if 0 <= row < SIZE and \
            0 <= col < SIZE and \
            board[row][col] == 0:
        board[row][col] = step
        if step == SIZE * SIZE:
            global total
            total += 1
            print(f"第{total}种解法")
            print_board(board)
        patrol(board, row - 2, col - 1, step + 1)
        patrol(board, row - 1, col - 2, step + 1)
        patrol(board, row + 1, col - 2, step + 1)
        patrol(board, row + 2, col - 1, step + 1)
        patrol(board, row + 2, col + 1, step + 1)
        patrol(board, row + 1, col + 2, step + 1)
        patrol(board, row - 1, col + 2, step + 1)
        patrol(board, row - 2, col + 1, step + 1)
        board[row][col] = 0


def warnsdorff():
    board = [[0] * SIZE for _ in range(SIZE)]
    patrol(board, SIZE - 1, SIZE + 1)


# warnsdorff()


"""
动态规划：
    求子列表中元素之和的最大值
"""


def max_sum_sublist():
    items = list(map(int, input().split()))
    overall = partial = items[0]
    for i in range(1, len(items)):
        partial = max(items[i], partial + items[i])
        overall = max(partial, overall)
    print(overall)


max_sum_sublist()